﻿using Godot;
using System.Collections.Generic;

public class SteamBoilerTankView : StoreView
{
    public TextureProgress thermal, water, steam, fuel;
    public Label thermalLabel, waterLabel, steamLabel;
    public List<Slot> Slots = new List<Slot>();
    public override void _Ready()
    {
        base._Ready();
        ResetShiftClick();
        Slots.Add(GetNode<Slot>("Input_0"));
        Slots.Add(GetNode<Slot>("Input_1"));
        Slots.Add(GetNode<Slot>("Input_2"));
        Slots.Add(GetNode<Slot>("Input_3"));
        Slots.Add(GetNode<Slot>("water_input")); //4
        Slots.Add(GetNode<Slot>("water_output")); //5
        Slots.Add(GetNode<Slot>("steam_input")); //6
        Slots.Add(GetNode<Slot>("steam_output"));//7
        thermal = GetNode<TextureProgress>("thermal_progress");
        water = GetNode<TextureProgress>("water_progress");
        steam = GetNode<TextureProgress>("steam_progress");
        fuel = GetNode<TextureProgress>("fuel_progress");
        thermalLabel = GetNode<Label>("thermal_progress/Label");
        waterLabel = GetNode<Label>("water_progress/Label");
        steamLabel = GetNode<Label>("steam_progress/Label");
        for (int i = 0; i < Slots.Count; i++)
        {
            Slots[i].index = i;
            Slots[i].OnClickEvent = ClickSlot;
            Slots[i].OnShiftClickEvent = ShiftClickSlot;
            Slots[i].HoldIn = BlockHoldIn;
            Slots[i].HoldOver = HoldOver;
        }
    }

    public override void Create()
    {
        base.Create();
    }

    public override void Updata(Player player)
    {
        base.Updata(player);
        if (block != null)
        {
            SteamBoilerTankEntity smte = (SteamBoilerTankEntity)block.blockEntity;
            for (int i = 0; i < Slots.Count; i++)
            {
                Slots[i].SetItemStack(smte.store.GetItemStack(Slots[i].index));
            }
            water.Value = (smte.water.GetPercentage() * 100f);
            waterLabel.Text = smte.water.ToString("ml");
            thermal.Value = (smte.thermal.GetPercentage() * 100f);
            thermalLabel.Text = smte.thermal.ToString("度");
            steam.Value = (smte.steam.GetPercentage() * 100f);
            steamLabel.Text = smte.steam.ToString("ml");
            fuel.Value = smte.fuel.GetPercentage() * 100f;
        }
    }
}
